CCIT
coder
Home
Courses
Contact
CCITcoder
Contents
Introduction to Java
History of Java
Features
General Format
Datatypes
DataType and Operation
Datatypes
Operators
Program Input
Conditional statements
If statement
Nested if
Ladder if statement
Ternary Operator
Switch statement
Iterative statements
While loop
for loop
do while
Nested loops
Functions
Introduction and types of function
Function arguments
Function returning value
OOPs
OOPs
Object
Access Specifiers
Methods Returning Value
Nesting of methods
method Overloading
Constructor
Constructor Overloading
Immutablemmutable Objects
String
String
String Buffer
Static Data members
Static Data members
Static Methods
Class Math
Static Initialization Block
Inherintance
Inherintance
Method Overriding
calling base method
Constructors and Inheritance
Types of Inheritance
Single Inhertance
Multi-level Inheritance
Hierarchical Inheritance
Polymorphisam
super keyword
this keyword
final keyword
Abstract keyword
Polymorphism
Aggregation
Interfaces
Applets
Applets
Class Applet
Class Graphics
class Color
AWT
AWT
Class Frame
Class Button
Event Delegation Modal
Class TextField
Class TextArea
Class Label
Class Component
Class Container
Class Checkbox
Class List
Class Choice
Class FlowLayout
Class BorderLayout
Class GridLayout
Class CardLayout
Class Panel
Class Font
Menus
Mouse Events
Window Events
MultiThreading
MultiThreading
class therad
Interface Runnable
I/o
I/O
Class Reader/writer
Class Input/output Stream
Preprocessor Commands
Preprocessor Commands
Exception Handling
Exception Handling
Types of exceptions
throw
finally
User-defined Exceptions
Nested Exceptions
Collection FrameWork
Collection FrameWork
ArrayList
Vector
Stack
Linked List
Array Deque
Hash Set
Hash Map
Contents
Introduction to Java
History of Java
Features
General Format
Datatypes
DataType and Operation
Datatypes
Operators
Program Input
Conditional statements
If statement
Nested if
Ladder if statement
Ternary Operator
Switch statement
Iterative statements
While loop
for loop
do while
Nested loops
Functions
Introduction and types of function
Function arguments
Function returning value
OOPs
OOPs
Object
Access Specifiers
Methods Returning Value
Nesting of methods
method Overloading
Constructor
Constructor Overloading
Immutablemmutable Objects
String
String
String Buffer
Static Data members
Static Data members
Static Methods
Class Math
Static Initialization Block
Inherintance
Inherintance
Method Overriding
calling base method
Constructors and Inheritance
Types of Inheritance
Single Inhertance
Multi-level Inheritance
Hierarchical Inheritance
Polymorphisam
super keyword
this keyword
final keyword
Abstract keyword
Polymorphism
Aggregation
Interfaces
Applets
Applets
Class Applet
Class Graphics
class Color
AWT
AWT
Class Frame
Class Button
Event Delegation Modal
Class TextField
Class TextArea
Class Label
Class Component
Class Container
Class Checkbox
Class List
Class Choice
Class FlowLayout
Class BorderLayout
Class GridLayout
Class CardLayout
Class Panel
Class Font
Menus
Mouse Events
Window Events
MultiThreading
MultiThreading
class therad
Interface Runnable
I/o
I/O
Class Reader/writer
Class Input/output Stream
Preprocessor Commands
Preprocessor Commands
Exception Handling
Exception Handling
Types of exceptions
throw
finally
User-defined Exceptions
Nested Exceptions
Collection FrameWork
Collection FrameWork
ArrayList
Vector
Stack
Linked List
Array Deque
Hash Set
Hash Map
Topics
Menu
String
String Buffer
Java StringBuffer class is used to create mutable (modifiable) String objects.
The StringBuffer class in Java is the same as String class except it is mutable i.e. it can be changed.
StringBuffer constructors
Objects of type StringBuffer can be created in different ways.
StringBuffer()
It reserves space for 16 characters.
For ex:
StringBuffer s = new StringBuffer();
System.out.println(s); =>
StringBuffer(int size)
It sets the buffer of initaially specified size.
For ex:
StringBuffer s = new StringBuffer(25);
System.out.println(s); =>
StringBuffer(String str)
It sets the initial contents of the StringBuffer object and reserves room for 16 more characters.
For ex:
StringBuffer s = new StringBuffer("CCIT");
System.out.println(s); => CCIT
String method
StringBuffer append(String s)
It is used to append the specified string with contents of StringBuffer.
It returns reference to same object.
The append( ) method is overloaded to add char , int , float etc.
append(char val)
append(Boolean val)
append(int val)
append(float val)
append(double val)
For ex:
StringBuffer s = new StringBuffer();
s.append("shree") ;
s.append(420);
System.out.println(s); => shree420
StringBuffer insert(int index,String s)
It is used to insert the specified string at the specified position.
It returns reference to same object.
The insert( ) method is overloaded to insert char , int , float etc.
insert(int index,char val)
insert(int index,boolean val)
insert(int index,int val)
insert(int index,float val)
insert(int index,double val)
For ex:
StringBuffer s = new StringBuffer();
s.append("RamSeeta");
s.insert(3,"Laxman");
System.out.println(s); => RamLaxmanSeeta
StringBuffer replace(int startIndex,int endIndex,String str)
is used to replace the string from specified startIndex to endIndex with given string.
Including startindex and excluding endindex.
It returns reference of same object.
For ex:
StringBuffer s=new StringBuffer("CCIT Rajapeth Amravati");
s.replace(5,13,"Gadge Nagar");
System.out.println(s); => CCIT Gadge Nagar Amravati
StringBuffer delete(int startIndex,int endIndex)
is used to delete the string from specified startIndex to endIndex.
Including startindex and excluding endindex.
It returns reference of same object.
For ex:
StringBuffer s=new StringBuffer("CCIT Rajapeth Amravati");
s.delete(5,13);
System.out.println(s); => CCITAmravati
StringBuffer reverse()
is used to reverse the contents of StringBuffer.
For ex:
StringBuffer s1=new StringBuffer("amravati");
s1.reverse();
System.out.println(s1); => itavarma
char charAt(int index)
returns char value from specified index.
For ex:
StringBuffer s1=new StringBuffer("Amravati");
char ch= s1.charAt(2);
System.out.println(ch); => r
String substring(int beginIndex)
returns a substring
Starting from beginIndex upto end.
For ex:
StringBuffer s1 = new StringBuffer("Amravati");
String s2 = s1.substring(4);
System.out.println(s2); => vati
String substring(int beginIndex,int endIndex)
returns a substring
Staring from beginIndex upto endIndex
Including beginIndex and excluding endIndex.
For ex:
StringBuffer s1 = new StringBuffer("Amravati");
String s2 = s1.substring(2,4);
System.out.println(s2); => ra
int length()
is used to return the length of the string i.e. total number of characters.
For ex:
StringBuffer s = new StringBuffer("CCIT");
int n = s.length();
System.out.println(n); => 4
int capacity()
is used to return the current capacity.
For ex:
StringBuffer s = new StringBuffer();
int n = s.capacity();
System.out.println(n); => 16
void ensureCapacity(int minimumCapacity)
is used to ensure the capacity at least equal to the given minimum.
For ex:
StringBuffer s = new StringBuffer();
s.ensureCapacity(100);
int n = s.capacity();
System.out.println(n); => 100
Previous topic
string
Next topic
Static Data members
Contents